//get请求
const BaseUrl = "https://37y5825u15.oicp.vip"
// const BaseUrl = "https://80bn6lj31000.vicp.fun"

function getRequest(url, data,response, error){
  wx.request({
          url: BaseUrl + `${url}`,//后台地址 
          method: 'GET',
          data: data,
          header: {
             'context-type': 'application/json'
            // 'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8',
        },
        success: (res) => {
            return response(res);
        },
        fail: (err) => {
            return error(err);
        },
    });
}
//post请求
function postRequest(url, data, response, error) {
    wx: wx.showLoading({
        title: "请求中",
        mask: true,
        success: (res) => {},
        fail: (res) => {},
        complete: (res) => {},
    });
    wx.request({
        url: BaseUrl + `${url}`, //后台地址
        method: "POST",
        data: data,
        header: {
            "content-type": "application/x-www-form-urlencoded;charset=utf-8",
            arenaId: wx.getStorageSync("venue").id,
        },
        success: (res) => {
            wx: wx.hideLoading({
                noConflict: true,
                success: (res) => {},
                fail: (res) => {},
                complete: (res) => {},
            });
            return response(res);
        },
        fail: (err) => {
            wx: wx.hideLoading({
                noConflict: true,
                success: (res) => {},
                fail: (res) => {},
                complete: (res) => {},
            });
            return error(err);
        },
    });
}
//post传的josn对象
function postRequestBody(url, data, response, error) {
    wx: wx.showLoading({
        title: "请求中",
        mask: true,
        success: (res) => {},
        fail: (res) => {},
        complete: (res) => {},
    });
    wx.request({
        url: BaseUrl + `${url}`, //后台地址
        method: "POST",
        data: data,
        header: {
            "context-type": "application/json",
        },
        success: (res) => {
            wx: wx.hideLoading({
                noConflict: true,
                success: (res) => {},
                fail: (res) => {},
                complete: (res) => {},
            });
            return response(res);
        },
        fail: (err) => {
            wx: wx.hideLoading({
                noConflict: true,
                success: (res) => {},
                fail: (res) => {},
                complete: (res) => {},
            });
            return error(err);
        },
    });
}
function putRequest(url, data, response, error) {
    wx: wx.showLoading({
        title: "请求中",
        mask: true,
        success: (res) => {},
        fail: (res) => {},
        complete: (res) => {},
    });
    wx.request({
        url: BaseUrl + `${url}`, //后台地址
        method: "PUT",
        data: data,
        header: {
            "context-type": "application/json",
        },
        success: (res) => {
            wx: wx.hideLoading({
                noConflict: true,
                success: (res) => {},
                fail: (res) => {},
                complete: (res) => {},
            });
            return response(res);
        },
        fail: (err) => {
            wx: wx.hideLoading({
                noConflict: true,
                success: (res) => {},
                fail: (res) => {},
                complete: (res) => {},
            });
            return error(err);
        },
    });
}
function delRequest(url, data, response, error) {
    wx.request({
        url: BaseUrl + `${url}`, //后台地址
        method: "DELETE",
        data: data,
        success: (res) => {
            return response(res);
        },
        fail: (err) => {
            return error(err);
        },
    });
}
export { getRequest, postRequest, postRequestBody, putRequest, delRequest };
